#include <math.h>

#include "Audio.h"
#include "Generate.h"
#include "RMS.h"

/**
 * Test for the RMS module
 *
 * @pipeline{Sine->RMS}
 **/
int main(int argc, char** argv) {
    DSP* dsp;

    for (int i=0; i<10; i++) {
        dsp = new DSP();

        float amp = 0.8;
        unsigned int freq = 300*(i+1);
        dsp->add((Module*)new Sine(dsp->getSampleRate(), amp, freq));

        /* To obtain a perfect RMS we should use a window long one sine period */
        RMS* rms = new RMS(dsp->getSampleRate(), 3.3);
        dsp->add((Module*)rms);

        Audio(dsp, 0.2);

        float expected = amp/sqrt(2.0);
        printf("Expected:   %0.4f\n", expected);
        printf("Calculated: %0.4f\n", rms->getValue());

        delete dsp;
    }

    return 0;
}
